package com.jvyou.app.ds.controller;



import com.jvyou.app.common.domain.model.PageResult;
import com.jvyou.app.ds.domain.dto.VehicleDto;
import com.jvyou.app.ds.domain.dto.VehicleUsageDto;
import com.jvyou.app.ds.domain.entity.Vehicle;
import com.jvyou.app.ds.domain.entity.VehicleUsage;
import com.jvyou.app.ds.service.VehicleUsageService;
import org.springframework.web.bind.annotation.*;
import lombok.RequiredArgsConstructor;
import cn.dev33.satoken.annotation.SaCheckPermission;
import com.jvyou.app.common.domain.model.Result;
import com.jvyou.app.common.enums.HttpCodeEnum;

import java.util.List;

/**
 * 车辆使用记录表(VehicleUsage)表控制层
 *
 * @author 橘柚
 * @since 2025-04-16 17:48:05
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/vehicleUsage")
public class VehicleUsageController  {
    
    private final VehicleUsageService vehicleUsageService;

    @GetMapping("/list")
    @SaCheckPermission("ds:vehicleUsage:list")
    public Result<List<VehicleUsage>> list(@ModelAttribute VehicleUsageDto vehicleUsageDto) {
        return Result.success(vehicleUsageService.listVehicleUsage(vehicleUsageDto));
    }

    @GetMapping("/page")
    @SaCheckPermission("ds:vehicleUsage:page")
    public Result<PageResult<VehicleUsage>> page(@ModelAttribute VehicleUsageDto vehicleUsageDto) {
        return Result.success(vehicleUsageService.pageVehicleUsage(vehicleUsageDto));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/{id}")
    @SaCheckPermission("ds:vehicleUsage:get")
    public Result<VehicleUsage> selectOne(@PathVariable Long id) {
        return Result.success(vehicleUsageService.getById(id));
    }

    /**
     * 新增数据
     *
     * @param vehicleUsage 实体对象
     * @return 新增结果
     */
    @PostMapping
    @SaCheckPermission("ds:vehicleUsage:insert")
    public Result<VehicleUsage> insert(@RequestBody VehicleUsage vehicleUsage) {
        boolean success = vehicleUsageService.save(vehicleUsage);
        return success ? Result.success(vehicleUsage) : Result.error(HttpCodeEnum.ADD_FAIL);
    }
    
}

